﻿/*
 * 源码己托管:https://git.oschina.net/dlgcy/dotnetcodes
 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DotNet.Utilities
{
    /// <summary>
    /// 路径帮助类;
    /// </summary>
    public static class PathHelper
    {
        /// <summary>
        /// 通过路径获得绝对路径;
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string GetAbsPathFromPath(string path)
        {
            if (!string.IsNullOrEmpty(path))
            {
                if (path.StartsWith("http:") || path.StartsWith("ftp:") || path.StartsWith("file:") || Path.IsPathRooted(path))
                {
                }
                else
                {
                    path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
                }
            }

            return path;
        }

        /// <summary>
        /// 通过路径获得绝对URI;
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Uri GetUriFromPath(string path)
        {
            Uri uri = null;
            path = GetAbsPathFromPath(path);
 
            if (!string.IsNullOrWhiteSpace(path))
            {
                uri = new Uri(path, UriKind.Absolute);
            }
 
            return uri;
        }
    }
}
